import pymysql

'''
数据库连接
'''

# Open database connection
db = pymysql.connect('localhost', 'root', 'root', 'py_test')  # 数据库url, 用户名, 密码, 数据库名称

# prepare a cursor object using cursor() method
cursor = db.cursor()

# execute SQL query using execute() method
cursor.execute('select version()')

# Fetch a single row using fetchone() method
data = cursor.fetchone()

print ("Database version : %s " % data)

# disconnect from server
db.close()


